<template>
	<view>
		<TopNavCustom :title="title"></TopNavCustom>
		<view class="process-bar">
			<text class="time">{{ time }}</text>
			<u-steps current="2" activeColor="#ee0013" class="steps">
				<u-steps-item title="进度情况"> </u-steps-item>
				<u-steps-item title="质量情况"> </u-steps-item>
				<u-steps-item title="安全情况"> </u-steps-item>
				<u-steps-item title="提交审批"> </u-steps-item>
			</u-steps>
		</view>
		<StepThree :node="_node" @saveData="saveData" @goToNext="goto" @returnLast="returnLast">
		</StepThree>
	</view>
</template>

<script>
	import _utils from "@/common/_utils.js";
	export default {
		onLoad(it) {
			this.temp = it;
			this._node = JSON.parse(decodeURIComponent(it.item));
			this.title = this._node.partName;
		},
		data() {
			return {
				_node: "",
				title: "",
				temp: "",
				time: uni.$u.timeFormat(false, "yyyy-mm-dd"),
			};
		},
		methods: {
			returnLast() {
				uni.navigateBack({
					delta: 1,
				});
			},
			//获取并存储第三步数据
			saveData(data) {
				let uuid = this._node.estateId + "ss";
				console.log("存储第三步数据的UUid :" + uuid);
				uni.setStorageSync(uuid, JSON.stringify(data));
				console.log(data);
			},
			async goto(tip) {
				//批量发送表单
				let flag1 = true;
				let flag2 = true;
				let flag3 = true;
				let _uuid1 = this._node.estateId + "pm";
				let _uuid2 = this._node.estateId + "qs";
				let _uuid3 = this._node.estateId + "ss";
				if (uni.getStorageSync(_uuid1)) {
					let _one = JSON.parse(uni.getStorageSync(_uuid1));
					//+ 判断—_one是否为空
					if (_one.length != 0) {
						for (let i = 0; i < _one.length; i++) {
							if (tip == 'save') {
								_one[i].progressStatus = 1
							} else {
								_one[i].progressStatus = 2
							}
						}
						//调用进度提交接口
						flag1 = await _utils.pushProgressArray(_one);
					}

				}
				if (uni.getStorageSync(_uuid2)) {
					let _two = JSON.parse(uni.getStorageSync(_uuid2));
					//+ 判断—_one是否为空 1待上传 ， 11已上传
					if (_two.length != 0) {
						for (let i = 0; i < _two.length; i++) {
							if (tip == 'save') {
								_two[i].issuesStatus = 1
							} else {
								_two[i].issuesStatus = 11
							}
						}
						//调用质量提交接口
						flag2 = await _utils.pushQuestionArray(_two);
					}
				}
				if (uni.getStorageSync(_uuid3)) {
					let _three = JSON.parse(uni.getStorageSync(_uuid3));
					//+ 判断—_one是否为空
					if (_three.length != 0) {
						for (let i = 0; i < _three.length; i++) {
							if (tip == 'save') {
								_three[i].issuesStatus = 1
							} else {
								_three[i].issuesStatus = 11
							}
						}
						//调用安全提交接口
						flag3 = await _utils.pushQuestionArray(_three);
					}
				}
				if (flag1 && flag2 && flag3) {
					uni.removeStorageSync(_uuid1)
					uni.removeStorageSync(_uuid2)
					uni.removeStorageSync(_uuid3)
					console.log("要跳转了！")
					if ('push' == tip) {
						let _url =
							"/pages/ihome/public_building_SF/public_building_SF?item=" + this.temp;
						uni.navigateTo({
							url: _url,
						});
					} else {
						uni.$showMsg("暂存成功，请前往数据继续提交");
						uni.$u.sleep(500).then(() => {
							uni.switchTab({
								url: '/pages/ihome/home/home'
							})
						})
					}
				}
			},
		},
	};
</script>

<style lang="scss" scoped>
	.process-bar {
		display: block;
		border: 1rpx solid #efefef;
		border-radius: 20rpx;
		background-color: #ffffff;
		padding: 30rpx;
		margin-bottom: 20rpx;

		.steps {
			margin-top: 45rpx;
		}
	}
</style>
